package com.abel.bigwater.data

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.JsonSerializer
import com.fasterxml.jackson.databind.SerializerProvider
import org.joda.time.DateTime

class JsonDateTimeSerializer(_pattern: String? = "yyyy-MM-dd'T'HH:mm:ss.SSSZZ") : JsonSerializer<DateTime>() {

    val pattern: String? = _pattern

    /**
     * Method that can be called to ask implementation to serialize
     * values of type this serializer handles.
     *
     * @param value Value to serialize; can **not** be null.
     * @param jgen Generator used to output resulting Json content
     * @param provider Provider that can be used to get serializers for
     * serializing Objects value contains, if any.
     */
    override fun serialize(value: DateTime?, jgen: JsonGenerator?, provider: SerializerProvider?) {
        jgen?.writeString(value?.toString(pattern))
    }
}